﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;

namespace tmp_GUI
{
    public class BillCount
    {
        public static void WriteBillInfo(DateTime writeDate, int pmsCount, int ptsCount, int pttCount){
            XmlTextWriter xmlwriter = new XmlTextWriter("BillInfo.xml", Encoding.UTF8);
            xmlwriter.Formatting = Formatting.Indented;
            xmlwriter.Indentation = 4;
            xmlwriter.WriteProcessingInstruction("xml", "version = '1.0' encoding = 'UTF-8'");
            xmlwriter.WriteComment("Author: Nguyen Hoang Duc\nDate created: " + DateTime.Now.ToString());
            xmlwriter.WriteStartElement("BillInformation");
            
            xmlwriter.WriteStartElement("Date");
            xmlwriter.WriteValue(writeDate.ToString());
            xmlwriter.WriteEndElement();

            xmlwriter.WriteStartElement("pmsCount");
            xmlwriter.WriteValue(pmsCount.ToString());
            xmlwriter.WriteEndElement();

            xmlwriter.WriteStartElement("ptsCount");
            xmlwriter.WriteValue(ptsCount.ToString());
            xmlwriter.WriteEndElement();

            xmlwriter.WriteStartElement("pttCount");
            xmlwriter.WriteValue(pttCount.ToString());
            xmlwriter.WriteEndElement();

            xmlwriter.Close();
        }
        public static DateTime GetDate(){
            return DateTime.Now;
        }
        public static List<int> getCount(int flag)
        {
            List<int> result = new List<int>();
            XmlTextReader reader = new XmlTextReader(new FileStream("BillInfo.xml", FileMode.Open));
            reader.ReadStartElement("BillInformation");

            while (reader.Read())
            {
                switch (flag)
                {
                    case 0:
                        try
                        {
                            result.Add(int.Parse(reader.ReadElementString("pmsCount")));
                            result.Add(int.Parse(reader.ReadElementString("ptsCount")));
                            result.Add(int.Parse(reader.ReadElementString("pttCount")));
                        }
                        catch (System.Exception ex)
                        {

                        }
                        break;
                    case 1:
                        try
                        {
                            result.Add(int.Parse(reader.ReadElementString("pmsCount")));
                        }
                        catch (System.Exception ex)
                        {

                        }
                        break;
                    case 2:
                        try
                        {
                            result.Add(int.Parse(reader.ReadElementString("ptsCount")));
                        }
                        catch (System.Exception ex)
                        {

                        }
                        break;
                    case 3:
                        try
                        {
                            result.Add(int.Parse(reader.ReadElementString("pttCount")));
                        }
                        catch (System.Exception ex)
                        {

                        }
                        break;
                }
            }
            reader.Close();
            return result;
        }
    }
}
